package com.kgc.service.edu.controller;

import com.kgc.common.result.Result;
import com.kgc.service.edu.entity.LoginUser;
import com.kgc.service.edu.service.LoginUserService;
import com.kgc.service.edu.service.SieUserService;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("user")
public class LoginController {


    private SieUserService sieUserService;
    private LoginUserService loginUserService;

    public LoginController(SieUserService sieUserService, LoginUserService loginUserService) {
        this.sieUserService = sieUserService;
        this.loginUserService = loginUserService;
    }

    @PostMapping("login")

    public Result login(@RequestBody LoginUser loginUser)
    {
        System.out.println(loginUser);
        /*LoginUser loginUser1=new LoginUser();
        String auser = loginUser1.getAuser();
        String userpassword = loginUser1.getUserpassword();*/

        LoginUser login = loginUserService.selByUser(loginUser);
        if(login==null){
            return Result.error().setMessage("用户不存在");
        }
        else{
        return Result.ok().setData("token",login);
        }
    }


    @GetMapping("info")
    public Result getInfo() {
        return Result.ok().setData("roles", "[admin]")
                .setData("name","admin")
                .setData("avatar","https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif?imageView2/1/");
    }

    @PostMapping("logout")
    public void logout(){

    }
}
